package com.ruoyi.center.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.center.domain.ResearchDirection;
import com.ruoyi.center.service.IResearchDirectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 研究方向Controller
 * 
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/center/direction")
public class ResearchDirectionController extends BaseController
{
    @Autowired
    private IResearchDirectionService researchDirectionService;

    /**
     * 查询研究方向列表
     */
    @PreAuthorize("@ss.hasPermi('center:direction:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResearchDirection researchDirection)
    {
        startPage();
        List<ResearchDirection> list = researchDirectionService.selectResearchDirectionList(researchDirection);
        return getDataTable(list);
    }

    /**
     * 导出研究方向列表
     */
    @PreAuthorize("@ss.hasPermi('center:direction:export')")
    @Log(title = "研究方向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResearchDirection researchDirection)
    {
        List<ResearchDirection> list = researchDirectionService.selectResearchDirectionList(researchDirection);
        ExcelUtil<ResearchDirection> util = new ExcelUtil<ResearchDirection>(ResearchDirection.class);
        util.exportExcel(response, list, "研究方向数据");
    }

    /**
     * 获取研究方向详细信息
     */
    @PreAuthorize("@ss.hasPermi('center:direction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(researchDirectionService.selectResearchDirectionById(id));
    }

    /**
     * 新增研究方向
     */
    @PreAuthorize("@ss.hasPermi('center:direction:add')")
    @Log(title = "研究方向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResearchDirection researchDirection)
    {
        return toAjax(researchDirectionService.insertResearchDirection(researchDirection));
    }

    /**
     * 修改研究方向
     */
    @PreAuthorize("@ss.hasPermi('center:direction:edit')")
    @Log(title = "研究方向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResearchDirection researchDirection)
    {
        return toAjax(researchDirectionService.updateResearchDirection(researchDirection));
    }

    /**
     * 删除研究方向
     */
    @PreAuthorize("@ss.hasPermi('center:direction:remove')")
    @Log(title = "研究方向", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(researchDirectionService.deleteResearchDirectionByIds(ids));
    }
}
